<template>
	<view class="content">
		用户名：<u--input placeholder="请输入用户名" border="surround" v-model="username"></u--input>
		密码：
		<u--input placeholder="请输入密码" border="surround" v-model="password"></u--input>

		<u-button text="登录" @click="submit"></u-button>

	</view>
</template>

<script>
	import {
		mapMutations,
		mapState
	} from "vuex"

	export default {
		computed: {
			...mapState(["userName", "userId", "token"])
		},
		data() {
			return {
				username: 'admin',
				password: 'admin123'
			}
		},
		onLoad() {
			// this.login({"userName":"wfq"})
			// alert(this.$store.state.userName)

			// uni.$u.http.post('/login', {
			// 	username: 'name',
			// 	password: '123456'
			// }).then(res => {
			// 	debugger
			// }).catch(err => {

			// })
		},
		methods: {
			...mapMutations(['login']),
			submit() {
				let that = this
				uni.$u.http.post('/appLogin', {
					username: this.username,
					password: this.password
				}).then(res => {
					if (res.code == 200) {
						that.login(res.data)
						uni.switchTab({
							url: '/pages/tab1/tab1'
						});
					}

				}).catch(err => {
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
